use base64::{engine::general_purpose, Engine};
use solutiont10::ZUC;

pub fn encryption(input: String) -> String {
    let input = pkcs7_pad(input.as_bytes(), 4);
    let zuc = ZUC::generate_keystream(&[0; 16], &[1; 16], input.len());
    let ciphertext: Vec<u8> = input.into_iter().zip(zuc).map(|(input, z)| input ^ z).collect();
    general_purpose::STANDARD.encode(ciphertext)
}

#[inline(always)]
fn pkcs7_pad(data: &[u8], block_size: usize) -> Vec<u8> {
    let padding_size = block_size - (data.len() % block_size);
    let mut padded_data = Vec::from(data);
    padded_data.extend(vec![padding_size as u8; padding_size]);
    padded_data
}